package com.yhs.snow.annoation;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AnnoationConfig {
    public  boolean validate() throws Exception {
        Field[] fields = this.getClass().getDeclaredFields();
        for(Field field:fields){
            NotNull notNull = field.getAnnotation(NotNull.class);
            if(notNull!=null){
                Method m = this.getClass().getMethod("get"+ getMethodName(field.getName()));
                Object obj = m.invoke(this);
                System.out.println(obj);
                if(obj==null){
                    System.out.println(field.getName()+notNull.message());
                }
            }

        }
        return true;
    }

    /**
     * 把一个字符串的第一个字母大写
     */
    private String getMethodName(String fildeName) throws Exception {
        byte[] items = fildeName.getBytes();
        items[0] = (byte) ((char) items[0] - 'a' + 'A');
        return new String(items);
    }
}
